-- SPDX-License-Identifier: GPL-3.0-or-later

local extension = Package:new("hanqing_cards", Package.CardPack)
extension.extensionName = "hanqing"

extension:loadSkillSkelsByPath("./packages/hanqing/pkg/hanqing_cards/skills")

Fk:loadTranslationTable{
  ["hanqing_cards"] = "汗青",
}

local bearing_rod = fk.CreateCard{
  name = "hanqing__bearing_rod",
  type = Card.TypeTrick,
  skill = "hanqing__bearing_rod_skill",
  special_skills = { "recast" },
}
extension:addCardSpec("hanqing__bearing_rod", Card.Club, 11)
Fk:loadTranslationTable{
  ["hanqing__bearing_rod"] = "负荆请罪",
  ["bearing_rod"] = "负荆请罪",
  [":hanqing__bearing_rod"] = "锦囊牌<br/>"..
  "<b>时机</b>：出牌阶段<br/>"..
  "<b>目标</b>：一名其他角色<br/>"..
  "<b>效果</b>：你对自己造成1点伤害并令目标角色回复1点体力，然后其可以移动其场上一张牌至你场上。",
}

local armchair_strategist = fk.CreateCard{
  name = "hanqing__armchair_strategist",
  type = Card.TypeTrick,
  skill = "hanqing__armchair_strategist_skill",
  is_passive = true,
}
extension:addCardSpec("hanqing__armchair_strategist", Card.Spade, 2)
Fk:loadTranslationTable{
  ["hanqing__armchair_strategist"] = "纸上谈兵",
  ["armchair_strategist"] = "纸上谈兵",
  [":hanqing__armchair_strategist"] = "锦囊牌<br/>"..
  "<b>时机</b>：回合结束时<br/>"..
  "<b>效果</b>：你可以将此牌当本回合使用过的一张基本牌或普通锦囊牌使用，若此牌未造成伤害，你获得此牌。",
}

local meteoric_rise = fk.CreateCard{
  name = "hanqing__meteoric_rise",
  type = Card.TypeTrick,
  sub_type = Card.SubtypeDelayedTrick,
  skill = "hanqing__meteoric_rise_skill",
}
extension:addCardSpec("hanqing__meteoric_rise", Card.Diamond, 8)
Fk:loadTranslationTable{
  ["hanqing__meteoric_rise"] = "平步青云",
  ["meteoric_rise"] = "平步青云",
  [":hanqing__meteoric_rise"] = "延时锦囊牌<br/>"..
  "<b>时机</b>：出牌阶段<br/>"..
  "<b>目标</b>：一名角色<br/>"..
  "<b>效果</b>：将此牌置于目标角色判定区内。其判定阶段进行判定：若结果不为♠，其加1点体力上限并回复1点体力。然后将【平步青云】置入弃牌堆。",
}

local he_gem = fk.CreateCard{
  name = "he_gem",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeTreasure,
  equip_skill = "#he_gem_skill",
}
extension:addCardSpec("he_gem", Card.Heart, 6)
Fk:loadTranslationTable{
  ["he_gem"] = "和氏璧",
  [":he_gem"] = "装备牌·宝物<br/>"..
  "<b>宝物技能</b>：摸牌阶段，你额外摸一张牌；你的手牌上限+1。【和氏璧】进入弃牌堆时，你将此牌交给一名其他角色；此牌被替换时，销毁之。",
}

local favorable_auspices = fk.CreateCard{
  name = "hanqing__favorable_auspices",
  type = Card.TypeTrick,
  skill = "hanqing__favorable_auspices_skill",
  multiple_targets = true,
}
extension:addCardSpec("hanqing__favorable_auspices", Card.Heart, 1)
Fk:loadTranslationTable{
  ["hanqing__favorable_auspices"] = "大吉大利",
  ["favorable_auspices"] = "大吉大利",
  [":hanqing__favorable_auspices"] = "锦囊牌<br/>"..
  "<b>时机</b>：出牌阶段<br/>"..
  "<b>目标</b>：所有角色<br/>"..
  "<b>效果</b>：目标角色各按手速顺序从牌堆顶摸一张牌，然后依次展示之。使用者和展示牌点数最大的角色各摸一张牌。",
}

local zhao_tiger_tally = fk.CreateCard{
  name = "&zhao_tiger_tally",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeTreasure,
  equip_skill = "#zhao_tiger_tally_skill",
}
extension:addCardSpec("zhao_tiger_tally", Card.Spade, 8)
Fk:loadTranslationTable{
  ["zhao_tiger_tally"] = "赵帅符",
  [":zhao_tiger_tally"] = "装备牌·宝物（衍生牌）<br/>"..
  "<b>宝物技能</b>：每回合限一次，当你弃置牌后，你可以获得一名其他角色的一张牌。当【赵帅符】进入弃牌堆时，销毁之。",
}

local vh_alliance = fk.CreateCard{
  name = "&hanqing__vh_alliance",
  type = Card.TypeTrick,
  skill = "hanqing__vh_alliance_skill",
  multiple_targets = true,
}
extension:addCardSpec("hanqing__vh_alliance", Card.Club, 1)
extension:addCardSpec("hanqing__vh_alliance", Card.Club, 6)
Fk:loadTranslationTable{
  ["hanqing__vh_alliance"] = "纵横捭阖",
  ["vh_alliance"] = "纵横捭阖",
  [":hanqing__vh_alliance"] = "锦囊牌（衍生牌）<br/>"..
  "<b>时机</b>：出牌阶段<br/>"..
  "<b>目标</b>：一至两名角色<br/>"..
  "<b>效果</b>：若目标角色未处于横置或连横状态，其进入<a href='hanqing__alliance_href'>合纵</a>状态；"..
  "若其处于横置或<a href='hanqing__alliance_href'>合纵</a>状态，其进入<a href='hanqing__alliance_href'>连横</a>状态；"..
  "若其处于<a href='hanqing__alliance_href'>连横</a>状态，重置其武将牌。",
}

local penal_code = fk.CreateCard{
  name = "&handing__penal_code",
  type = Card.TypeBasic,
  skill = "handing__penal_code_skill",
}
extension:addCardSpec("handing__penal_code")
Fk:loadTranslationTable{
  ["handing__penal_code"] = "法经",
  ["penal_code"] = "法经",
  [":handing__penal_code"] = "律（衍生牌）<br/>"..
  "<b>效果</b>：当判定牌因生效进入弃牌堆后，或当锦囊牌于失效后进入弃牌堆后，若《法经》处于游戏外，将这些牌置于《法经》上。<br>"..
  "<a href='hanqing_reform'>革制</a>：进行四次判定，每有一张判定牌结果花色为♠，你便摸一张牌。",
  ["hanqing_reform"] = "<b>革制</b>：<br>当“律”牌移出游戏后，立刻触发的效果。",
}

local propriety__precept = fk.CreateCard{
  name = "&propriety__precept",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeTreasure,
  equip_skill = "#propriety__precept_skill",
}
extension:addCardSpec("propriety__precept")
Fk:loadTranslationTable{
  ["propriety__precept"] = "礼戒·愚律",
  [":propriety__precept"] = "律·宝物（衍生牌）<br/>"..
  "<b>效果</b>：此牌亦视为宝物，你对神商鞅或主公造成伤害后弃置。<br>"..
  "<a href='hanqing_reform'>革制</a>：你令自己本回合不能回复体力和造成伤害，然后你可以废除宝物栏。",
}

local righteousness__precept = fk.CreateCard{
  name = "&righteousness__precept",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeWeapon,
  attack_range = 1,
  equip_skill = "#righteousness__precept_skill",
}
extension:addCardSpec("righteousness__precept")
Fk:loadTranslationTable{
  ["righteousness__precept"] = "义戒·弱律",
  [":righteousness__precept"] = "律·武器（衍生牌）<br/>"..
  "<b>效果</b>：此牌亦视为武器，你使用【杀】后弃置。<br>"..
  "<a href='hanqing_reform'>革制</a>：神商鞅视为对你使用一张无伤害来源的【杀】，然后你可以废除武器栏。",
}

local benevolence__precept = fk.CreateCard{
  name = "&benevolence__precept",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeDefensiveRide,
  equip_skill = "#benevolence__precept_skill",
}
extension:addCardSpec("benevolence__precept")
Fk:loadTranslationTable{
  ["benevolence__precept"] = "仁戒·贫律",
  [":benevolence__precept"] = "律·防御坐骑（衍生牌）<br/>"..
  "<b>效果</b>：此牌亦视为防御坐骑，你手牌数变为最多时弃置。<br>"..
  "<a href='hanqing_reform'>革制</a>：你明置两张手牌，神商鞅将之交给除你以外的一名角色，然后你可以废除防御坐骑栏。",
}

local wisdom__precept = fk.CreateCard{
  name = "&wisdom__precept",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeOffensiveRide,
  equip_skill = "#wisdom__precept_skill",
}
extension:addCardSpec("wisdom__precept")
Fk:loadTranslationTable{
  ["wisdom__precept"] = "智戒·疲律",
  [":wisdom__precept"] = "律·进攻坐骑（衍生牌）<br/>"..
  "<b>效果</b>：此牌亦视为进攻坐骑，你对攻击范围外角色使用牌后弃置。<br>"..
  "<a href='hanqing_reform'>革制</a>：你弃置手牌中的非基本牌，然后你可以废除进攻坐骑栏。",
}

local integrity__precept = fk.CreateCard{
  name = "&integrity__precept",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeArmor,
  equip_skill = "#integrity__precept_skill",
}
extension:addCardSpec("integrity__precept")
Fk:loadTranslationTable{
  ["integrity__precept"] = "信戒·辱律",
  [":integrity__precept"] = "律·防具（衍生牌）<br/>"..
  "<b>效果</b>：此牌亦视为防具，你受到伤害后弃置。<br>"..
  "<a href='hanqing_reform'>革制</a>：你弃置手牌中所有【杀】并视为使用一张【决斗】，然后你可以废除防具栏。",
}

local shendao_twelve_chapters = fk.CreateCard{
  name = "&shendao_twelve_chapters",
  type = Card.TypeBasic,
  skill = "shendao_twelve_chapters_skill",
}
extension:addCardSpec("shendao_twelve_chapters")
Fk:loadTranslationTable{
  ["shendao_twelve_chapters"] = "十二论",
  [":shendao_twelve_chapters"] = "律（衍生牌）<br/>"..
  "<b>效果</b>：<a href='hanqing_reform'>革制</a>：失去此牌的角色每有一项为全场最大，便摸一张牌：体力值、手牌数、装备区牌数；"..
  "若均不满足，其失去1点体力。",
}

local chixiao_sword = fk.CreateCard{
  name = "&chixiao_sword",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeWeapon,
  attack_range = 2,
  equip_skill = "#chixiao_sword_skill",
}
extension:addCardSpec("chixiao_sword", Card.Heart, 7)
Fk:loadTranslationTable{
  ["chixiao_sword"] = "赤霄剑",
  [":chixiao_sword"] = "装备牌·武器（衍生牌）<br/>"..
  "<b>攻击范围</b>：2<br/>"..
  "<b>武器技能</b>：当你使用【杀】指定目标后，或成为【杀】的目标后，你可以弃置两张牌（不足则全弃，无牌则不弃），摸两张牌。",
}

local taigong_tactics = fk.CreateCard{
  name = "&hanqing__taigong_tactics",
  type = Card.TypeEquip,
  sub_type = Card.SubtypeTreasure,
  equip_skill = "hanqing__taigong_tactics_skill&",
  on_install = function(self, room, player)
    Treasure.onInstall(self, room, player)
    room = room ---@type Room
    room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
      local use = e.data
      if use.from == player and use.card:isCommonTrick() then
        room:setPlayerMark(player, "hanqing__taigong_tactics", use.card.name)
        return true
      end
    end, -1)
  end,
  on_uninstall = function(self, room, player)
    Treasure.onUninstall(self, room, player)
    room:setPlayerMark(player, "hanqing__taigong_tactics", 0)
  end,
}
extension:addCardSpec("hanqing__taigong_tactics", Card.Club, 1)
Fk:loadTranslationTable{
  ["hanqing__taigong_tactics"] = "太公兵法",
  [":hanqing__taigong_tactics"] = "装备牌·宝物（衍生牌）<br/>"..
  "<b>宝物技能</b>：若你没有手牌，你可以摸一张牌，视为使用你上次使用的普通锦囊牌。",
}

extension:loadCardSkels {
  bearing_rod,
  armchair_strategist,
  meteoric_rise,
  he_gem,

  zhao_tiger_tally,
  vh_alliance,
  penal_code,
  propriety__precept,
  righteousness__precept,
  benevolence__precept,
  wisdom__precept,
  integrity__precept,
  shendao_twelve_chapters,
  chixiao_sword,
  taigong_tactics,
  favorable_auspices,
}

return extension
